package com.shortvedio.auth.controller;

import com.shortvedio.ucenter.model.Result;
import com.shortvedio.ucenter.model.dto.AuthDto;
import com.shortvedio.ucenter.service.AuthService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author Mr.M
 * @version 1.0
 * @description TODO
 * @date 2023/2/24 15:13
 */
@Slf4j
@RestController
public class LoginController {

    @Autowired
    private AuthService authService;

//    @RequestMapping("/wxLogin")
//    public String wxLogin(String code, String state) throws IOException {
//        log.debug("微信扫码回调,code:{},state:{}", code, state);
//        //远程调用微信请令牌，拿到令牌查询用户信息，将用户信息写入本项目数据库
//        SUsersLogin user = wxAuthService.wxAuth(code);
//
//        if (user == null) {
//            return "redirect:http://www.51xuecheng.cn/error.html";
//        }
//        String username = user.getUserName();
//        return "redirect:http://www.51xuecheng.cn/sign.html?username=" + username + "&authType=wx";
//    }

    @PostMapping("/password_login")
    public Result passwordLogin(@RequestBody AuthDto authDto){
        Result result = authService.passwordLogin(authDto);
        return result;
    }
}
